<template>
	<u-popup :show.sync="showPopup" :round="10" mode="bottom" @close="close">
		<view class="popup_content">
			<view class="top_box">
				<view class="btn">
					切换仓库
				</view>
				<view class="ipt_box">
					<u-icon name="search" color="#c0c0c0" size="28"></u-icon>
					<input placeholder="关键字查找仓库" type="text" />
				</view>
				<view @click="close()" class="text_box">
					关闭
				</view>
			</view>
			<!-- 仓库列表 -->
			<view class="stashList_box">
				<view class="stashItem_box" v-for="(item,index) in StashList" :key="item.ware_id">
					<view class="left">
						<u-icon name="home-fill" color="#1296db" size="40"></u-icon>
						<text>{{item.ware_name}}</text>
					</view>
					<view @click="selectStash(item)" class="right">
						选择
					</view>
				</view>
			</view>
		</view>
	</u-popup>
</template>
<script>
	import {
		getWareHouseListApi
	} from '@/api/my.js'
	export default {
		data() {
			return {
				StashList: []
			}
		},
		props: {
			showPopup: {
				type: Boolean,
				default: false
			}
		},
		mounted() {
			this.getWareHouseList()
		},
		methods: {

			close() {
				this.$emit('update:showPopup', false)
			},
			//获取仓库
			async getWareHouseList() {
				const {
					data: {
						data
					}
				} = await getWareHouseListApi()
				this.StashList = data
				this.$store.state.user.stashInfo.ware_name ? '' : this.$store.commit('user/SET_STASH_INFO', this
					.StashList[0])
				this.$parent.putInAndOutAndWarning()

			},
			//选择仓库
			selectStash(item) {
				const that = this
				uni.showModal({
					content: `确定要切换为${item.ware_name}吗？`,
					success: function(res) {
						if (res.confirm) {
							that.$store.commit('user/SET_STASH_INFO', item)
							that.$parent.putInAndOutAndWarning()
							that.close()
							uni.showToast({
								icon: 'none',
								title: '仓库切换成功',
								duration: 1000
							});
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			}
		},
	}
</script>

<style lang="scss" scoped>
	.popup_content {
		height: 80vh;

		.top_box {
			display: flex;
			justify-content: space-between;
			font-size: 26rpx;
			padding: 20rpx;

			.btn {
				width: 120rpx;
				height: 70rpx;
				font-weight: 700;
				color: #000;
				text-align: center;
				line-height: 70rpx;


			}

			.ipt_box {
				display: flex;
				align-items: center;
				width: 480rpx;
				height: 70rpx;
				padding: 0 20rpx;
				background-color: #f2f2f2;
				border-radius: 35rpx;
				box-sizing: border-box;

				input {
					margin-left: 20rpx;
				}
			}

			.text_box {
				color: #60aeff;
				line-height: 70rpx;
			}
		}

		.stashItem_box {
			border-bottom: 1px solid #f2f2f2;
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 20rpx;

			.left {
				display: flex;
				align-items: center;
				font-weight: 700;

				text {
					margin-left: 20rpx;
				}
			}

			.right {
				width: 180rpx;
				height: 60rpx;
				background-color: #39cccc;
				color: #fff;
				text-align: center;
				line-height: 60rpx;
				border-radius: 35rpx;
			}
		}
	}
</style>